@extends('layouts.admin.application')
@section('content')

    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">企业管理</strong> /
                    <small>List</small>
                </div>
            </div>
            @include('admin._flash')
            <hr>

            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-6">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-s">
                            <a href="/admin/recustomer/create" type="button" class="am-btn am-btn-default"><span
                                        class="am-icon-plus"></span> 新增</a>
                            {{--<button type="button" class="am-btn am-btn-default delete_all"><span--}}
                            {{--class="am-icon-trash-o"></span> 删除--}}
                            {{--</button>--}}


                        </div>
                    </div>
                </div>
            </div>
            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-12">
                    <form class="am-form-inline" method="get">
                        <div class="am-form-group">
                            <div class="am-input-group am-input-group-sm">
                                <input type="text" class="am-form-field" name="name"
                                       value="{{Request::input('name')}}" placeholder="企业名搜索">
                            </div>


                            <select data-am-selected="{btnSize: 'sm', maxHeight: 360, searchBox: 1}"
                                    name="store_id">
                                <option value="-1">所有门店</option>
                                @foreach($cates as $c)
                                <option value="{{$c->id}}"
                                @if(Request::input('store_id')==$c->id) selected @endif>{{$c->name}}</option>
                                @endforeach
                            </select>
                        </div>

                        <div class="am-form-group" style="margin-top: 3px">
                            <button type="submit" class="am-btn am-btn-default am-btn-sm">查询</button>
                            <a href="/admin/recustomer" class="am-btn am-btn-default am-btn-sm">重置</a>
                        </div>
                    </form>
                </div>

            </div>
            <hr>


            <div class="am-g">
                <div class="am-u-sm-12">
                    <form class="am-form">
                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr style="font-size: 1.6rem">
                                <th><input class="check_all" type="checkbox"></th>
                                <th class="table-id">ID</th>
                                <th class="table-thumb">企业名</th>
                                <th class="table-type">联系人姓名</th>
                                <th class="table-type">联系人电话</th>
                                <th class="table-type">余额</th>
                                <th class="table-type">可同时在店</th>
                                <th class="table-type">到店次数</th>
                                <th class="table-type">套餐开通时间</th>
                                <th class="table-type">套餐到期时间</th>
                                <th class="table-type">是否可用</th>
                                <th class="table-type">绑定成员</th>
                                <th class="table-type"style="width: 90px">绑定员工消费记录</th>
                                <th class="table-type">加入Key</th>
                                <th class="table-type">更新Key</th>
                                <th class="table-type">发送Key</th>
                                <th class="table-set">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($cs as  $k=> $c)
                                <tr data-id="{{$c->id}}" style="font-size: 1.6rem">
                                    <th><input class="checked_id" name="checked_id[]" value="" type="checkbox"></th>
                                    <td>{{$k+1}}</td>

                                    <td>

                                            {{$c->name}}

                                    </td>

                                    <td>
                                        {{$c->linkman_name}}
                                    </td>
                                    <td class="am-hide-sm-only">
                                        <label class=" am-btn-secondary am-btn-s am-radius">
                                            {{$c->linkman_tel}}
                                        </label>
                                    </td>

                                    <td>
                                           {{$c->money}}元
                                    </td>
                                    <td>
                                        {{$c->staff_number}}人
                                    </td>
                                    <td>

                                        <label class=" am-btn-secondary am-btn-s am-radius">
                                            {{$c->come_time}}次
                                        </label>

                                    </td>


                                    <td>
                                        {{$c->start_at}}
                                    </td>
                                    <td>
                                        {{$c->end_at}}
                                    </td>

                                    @if(strtotime($c->end_at) - time()>0)
                                        <td>
                                            <label class=" am-btn-success am-btn am-btn-xs am-radius">
                                                是
                                            </label>

                                        </td>
                                    @endif
                                    @if(strtotime($c->end_at) - time()<=0)
                                        <td>
                                            <label class=" am-btn-danger am-btn am-btn-xs am-radius">
                                                否
                                            </label>

                                        </td>
                                    @endif

                                    <td>
                                        <a href="/admin/oncustomer?company_id={{$c->id}}"> <label class="am-btn-danger am-btn am-btn-xs am-radius ">
                                                查看
                                            </label></a>
                                    </td>

                                    <td>
                                        <a href="/admin/order/order?company_id={{$c->id}}&pay_way=4"> <label class="am-btn-danger am-btn am-btn-xs am-radius ">
                                                查看
                                            </label></a>
                                    </td>
                                    <td>
                                        <label class=" am-btn-default am-btn-s am-radius">
                                            {{$c->key}}
                                        </label>
                                    </td>

                                    <td>
                                        <label class="am-btn-danger am-btn am-btn-xs am-radius gx">
                                            更新
                                        </label>
                                    </td>
                                    <td>
                                        <label class="am-btn-danger am-btn am-btn-xs am-radius gxx">
                                            发送
                                        </label>
                                    </td>
                                    <td>
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">

                                                <a href="/admin/recustomer/showplan/{{$c->id}}"
                                                   class="am-btn am-btn-success am-btn-xs"><span
                                                            class="am-icon-pencil-square-o"></span> 续开或更换套餐
                                                </a>
                                                <a href="/admin/recustomer/deposit/{{$c->id}}"
                                                   class="am-btn am-btn-default am-btn-xs"><span
                                                            class="am-icon-pencil-square-o"></span> 余额充值
                                                </a>

                                                <a href="/admin/recustomer/{{$c->id}}/edit"
                                                   class="am-btn am-btn-primary am-btn-xs"><span
                                                            class="am-icon-pencil-square-o"></span> 编辑
                                                </a>

                                                <a href="/admin/recustomer/{{$c->id}}"
                                                   data-method="delete"
                                                   data-token="{{csrf_token()}}" data-confirm="确认删除吗?"
                                                   class="am-btn am-btn-danger am-btn-xs del_one">
                                                    <span class="am-icon-trash-o"></span> 删除
                                                </a>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            @endforeach


                            </tbody>
                        </table>
                        共 {{$cs->total()}} 条记录

                        <div class="am-cf">
                            <div class="am-fr">
                                {!! $cs->appends(Request::all())->links() !!}
                            </div>
                        </div>
                        <hr/>
                        <p>注：.....</p>
                    </form>
                </div>

            </div>
        </div>

        <footer class="admin-content-footer">
            <hr>
            <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
        </footer>

    </div>


@endsection
@section('js')
    <script>
        $(function () {

            //改变性别
            $('.gx').click(function () {
                //   alert(111);

                var id = $(this).parents('tr').data('id');
// console.log(id);exit;
                var _this = $(this);
                $.ajax({
                    type: 'PATCH',
                    url: '/admin/recustomer/change_key',
                    data: {id: id},
                    success: function () {
                        // _this.toggleClass('am-icon-male am-icon-female');
                        location.href = location.href;

                    }
                })

            })

            $('.gxx').click(function () {
                //   alert(111);

                var id = $(this).parents('tr').data('id');
// console.log(id);exit;
                var _this = $(this);
                $.ajax({
                    type: 'PATCH',
                    url: '/admin/recustomer/sendSms',
                    data: {id: id},
                    success: function (res) {
                        // _this.toggleClass('am-icon-male am-icon-female');
                       if(res==1){
                           alert('发送成功')
                       }

                    }
                })

            })
        })
    </script>
@endsection